<?php
if (!defined('CURRENT_PATH')){
	die('Hacking attempt');
	}
	$up=spClass('upload');
if($_REQUEST['act']&&$_REQUEST['act']=='save'){
	//dump($this->spArgs());
	mysql_query("set sql_mode=''");
	$saveMapArr=array('fileName'=>'upload_name','file_url'=>'upload_url','showOrder'=>'show_order','file_status'=>'upload_status');
	if($_REQUEST['id']){
		$update_id=intval($_REQUEST['id']);
		$row=array('upload_author'=>$_SESSION['adminUserName'],'upload_dategmt'=>time());
		foreach($saveMapArr as $id=>$v){
			$tempArr=array($v=>$this->spArgs($id));
			$row=array_merge($row,$tempArr);
		}
		$up->update($conditions=array('id'=>$update_id),$row);
		$this->success('恭喜！修改成功！');
	}else{
		$newrow=array('id'=>'','upload_author'=>$_SESSION['adminUserName'],'upload_dategmt'=>time());
		foreach($saveMapArr as $id=>$v){
			$tempArr=array($v=>$this->spArgs($id));
			$newrow=array_merge($newrow,$tempArr);
		}
		$up->create($newrow);
		$this->success('恭喜！添加文件成功！');				
	}		
}else if($_REQUEST['act']&&$_REQUEST['act']=='add'){
		$this->display('management/file_add.html');		
}else if($_REQUEST['act']&&$_REQUEST['id']&&$_REQUEST['act']=='modify'){
		$id=intval($_REQUEST['id']);
		$res=$up->find($conditions=array('id'=>$id));
		//dump($res);
		$this->res=$res;
		$this->display('management/upload_modify.html');	
}else if($_REQUEST['act']&&$_REQUEST['id']&&$_REQUEST['act']=='del'){
		$id=intval($_REQUEST['id']);
		$res=$up->delete($conditions=array('id'=>$id));
		$this->success("恭喜，操作成功！");
}else{
	$page=isset($_GET[page])?$_GET[page]:1;
	$res=$up->spPager($this->spArgs('page', $page),18)->findAll($conditions=array(upload_id=>0));
	$this->res=$res;
	$this->pager = $up->spPager()->getPager();
	$this->pageflag=0;
	$this->display('management/file_manage.html');		
	}